<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>填写试用报告</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />

</head>

<body>
    <div class="aui-timeline" style="margin-top:0.8rem">
        <div class="aui-timeline-item">
            <div class="aui-timeline-item-label aui-bg-info text-light">Step.1</div>
            <div class="aui-timeline-item-inner">
                <div class="aui-card-list">
                    <div class="aui-card-list-header aui-border-b">
                        <div>试用内容：</div>

                    </div>
                    <div class="aui-card-list-content-padded" id="good-name">

                    </div>
                </div>
            </div>
        </div>
        <div class="aui-timeline-item">
            <div class="aui-timeline-item-label aui-bg-warning text-light">Step.2</div>
            <div class="aui-timeline-item-inner">
                <div class="aui-card-list">
                    <div class="aui-card-list-header aui-border-b">上传试用图片：</div>
                    <div class="aui-card-list-content-padded">
                        <div class="aui-row aui-row-padded">
                            <div class="aui-col-xs-4" onclick="fnUploadPic();">
                                <img src="./img/add_pic.png" id="avatar" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="aui-timeline-item">
            <div class="aui-timeline-item-label aui-bg-success text-light">Step.3</div>
            <div class="aui-timeline-item-inner">
                <div class="aui-card-list">
                    <div class="aui-card-list-header aui-border-b">试用过程和体验：</div>
                    <div class="aui-card-list-content">
                        <textarea name="name" id="content" style="background-color:#ccc;border:1px solid #f7f7f7;height:5rem;" placeholder="请输入试用过程和体验"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function() {
        var goodName = api.pageParam.goodName;

        $("#good-name").html(goodName);
    };

    function fnUploadPic() {
        api.actionSheet({
            title: '上传照片',
            cancelTitle: '取消',
            buttons: ['拍照', '手机相册']
        }, function(ret, err) {
            if (ret) {
                getPicture(ret.buttonIndex);
            }
        });
    };

    function getPicture(sourceType) {
        switch (sourceType) {
            case 1:
                var operate_type = 'camera';
                break;
            case 2:
                var operate_type = 'album';
                break;

        }
        //获取一张图片
        api.getPicture({
            sourceType: operate_type, //
            encodingType: 'jpg',
            mediaValue: 'all',
            destinationType: 'base64',
            allowEdit: true,
            quality: 50,
            targetWidth: 100,
            targetHeight: 100,
            saveToPhotoAlbum: false
        }, function(ret, err) {
            if (ret.data) {
                //saveImg(ret.data,valueId,imgId);
                saveImg(ret.data);
                //$api.byId('avatar').src=ret.data;
            } else {
                api.toast({
                    msg: '图像获取失败',
                    duration: 3000,
                    location: 'bottom'
                })
            }
        });


    }
    //保存剪辑图像
    function saveImg(path) {
        api.showProgress({
            title: '上传中...',
            text: '先喝杯茶...',
        });
        //上传剪辑后的图像到服务器
        api.ajax({
            // report : false,
            url: SITE_URL + 'index.php?m=api&c=appnew&a=ajax_img_aliyun',
            //这里是我们约定好的后台上传图片的位置 ，你可以根据你的需求来改
            method: 'post',
            cache: 'false',
            timeout: 30,
            dataTpye: 'json',
            data: {
                files: {
                    file: path
                }
            }
        }, function(ret, err) {
            if(ret.status==1){
              api.hideProgress();
              $api.byId('avatar').src=ret.msg.src;
            }

        });
    };

    function fnSubmit(){
        var userInfo = $api.getStorage('userInfo');
        //获取数据app中存入的数据然后分配到模板中；
        var random = userInfo.random;
        var userid = userInfo.userid;
        //获取需要的参数
        var orderId = api.pageParam.orderId;
        var thumb=$("#avatar").attr("src");
        var content=$("#content").val();
          api.ajax({
              url: SITE_URL+'index.php?m=api&c=appnew&a=fill_trial_report',
              method: 'POST',
                    data: {
                        values: {
                            "userid": userid,
                            "random": random,
                            "order_id":orderId,
                            "thumb":thumb,
                            "content":content
                        }
                    }
                }, function(ret, err) {
                  if(ret.status==1){
                    alert(ret.msg);
                    api.closeWin();
                    closeWin();
                  }else{
                    alert(ret.msg);
                  }

                });

          }
          function closeWin() {
              GoToRefresh(); //关闭窗口时先刷新指定窗口页面,如需刷新主界面，name请填写root

          }


          function GoToRefresh() {
              api.execScript({
                  name: 'task_ing',
                  frameName: 'task_ing_frame_1',
                  script: 'fnGetData(3);'
              });
          }
      </script>

      </html>
